import bisect
class TopVotedCandidate(object):

    def __init__(self, persons, times):
        """
        :type persons: List[int]
        :type times: List[int]
        """
        self.persons = persons
        self.times = times
        n = len(self.persons)
        self.win = [-1] * n
        self.count = [0] * n
        self.count[persons[0]] += 1
        self.win[0] = persons[0]
        now_max = 1
        now_win = persons[0]
        for i in range(1, n):
            self.count[persons[i]] += 1
            if self.count[persons[i]] >= now_max:
                now_max = self.count[persons[i]]
                now_win = persons[i]
            self.win[i] = now_win


    def q(self, t):
        """
        :type t: int
        :rtype: int
        """
        index = bisect.bisect(self.times, t)
        return self.win[index - 1]

